@include('admin.header')

<link href="/static/admin/css/myadmin.css"  rel="stylesheet" type="text/css">

<div class="wrap">
    <div class="margin-bottom-20">
        <div class="grey-nav">
            @if(Request::get('source_type')==1)
                <span>手机支付款提现</span>
            @elseif(Request::get('source_type')==2)
                <span>POS机支付款提现</span>
            @elseif(Request::get('source_type')==3)
                <span>让利存款提现</span>
            @endif
        <div class="pull-right">
                <button name="" class="btn btn-primary" type="button" onclick="window.location.href='{{url('/settle/apply_withdraw?source_type=').Request::get('source_type')}}'"><i class="Hui-iconfont"></i>申请提现</button>
            </div>
        </div>
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                @if(Request::get('source_type')==3)
                    <th class="text-center">总存款金额</th>
                @else
                    <th class="text-center">总营业额</th>
                @endif
                <th class="text-center">可提现金额</th>
                <th class="text-center">已提现金额</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td class="text-center">
                    {{$data['income']}}
                    @if(Request::get('source_type')==3)
                        <br><a class="view" data-url="{{url('settle/deposit')}}" data-title="存款记录">查看详情</a>
                    @endif
                </td>
                <td class="text-center">
                    {{$data['realIncome']-$data['cashed']}}
                    @if(Request::get('source_type')==3)
                        <br><a class="view" data-url="{{url('settle/deposit?unfreeze=true')}}" data-title="存款解冻记录">查看详情</a>
                    @endif
                </td>
                <td class="text-center">{{floatval($data['cashed'])}}</td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="grey-nav">
        <span>提现记录</span>
        <div class="pull-right">
            <button class="btn btn-success" id="excel">导出为Excel</button>
        </div>
    </div>
    <div>
        <div class="row">
            <div class="col-12">
                <span>排序：</span>
                <select name="sort">
                    <option value="asc" @if(Request::get('sort')=='asc') selected @endif>提现申请时间升序</option>
                    <option value="desc" @if(Request::get('sort')=='desc') selected @endif>提现申请时间降序</option>
                </select>
                <span>每页显示：</span>
                <select name="pagesize">
                    <option value="10" @if(Request::get('pagesize')==10) selected @endif>10</option>
                    <option value="25" @if(Request::get('pagesize')==25) selected @endif>25</option>
                    <option value="50" @if(Request::get('pagesize')==50) selected @endif>50</option>
                    <option value="100" @if(Request::get('pagesize')==100) selected @endif>100</option>
                </select>
                <span>条</span>
            </div>
        </div>
    </div>
    <form class="form-horizontal js-ajax-form" method="post" novalidate="novalidate">
        <table class="table table-hover table-bordered">
            <thead>
                <tr>
                    <th class="text-center">序号</th>
                    <th class="text-center">提现状态</th>
                    <th class="text-center">提现金额</th>
                    <th class="text-center">手续费</th>
                    <th class="text-center">申请时间</th>
                </tr>
            </thead>
            <tbody>
                @foreach($data['lists'] as $k=>$item)
                <tr>
                    <td class="text-center">{{$k+1}}</td>
                    <td class="text-center">
                        @if($item->apply_status==1)
                            申请中
                        @elseif($item->apply_status==2)
                            打款中
                        @elseif($item->apply_status==3)
                            打款成功
                        @elseif($item->apply_status==3)
                            打款失败
                        @else
                            未知状态
                        @endif
                    </td>
                    <td class="text-center">{{floatval($item->apply_amount)}}</td>
                    <td class="text-center">{{floatval($item->poundage)}}</td>
                    <td class="text-center">{{$item->apply_time}}</td>
                </tr>
                @endforeach
            </tbody>
        </table>
        <!-- 分页 -->
        @if (!empty($data['lists']))
            <div class="page_list">
                {{$data['lists']->appends(Request::input())->links()}}
            </div>
        @endif
    </form>
</div>
<script src="/static/js/common.js"></script>
<script src="/static/js/H-ui.min.js"></script>
<script>
    //数组Unique
    Array.prototype.unique = function(){
        var res = [];
        var json = {};
        for(var i = 0; i < this.length; i++){
            if(!json[this[i]]){
                res.push(this[i]);
                json[this[i]] = 1;
            }
        }
        return res;
    };

    //点击查看详情
    $('body').on('click','.view',function () {
        //iframe层
        layer.open({
            type: 2,
            title: this.getAttribute('data-title'),
            shadeClose: true,
            shade: 0.8,
            area: ['99%', '99%'],
            content: this.getAttribute('data-url')
        });
    });


    //选择排序
    $("select[name=sort]").on('change',function () {
        window.location.href=(setUrlParam(window.location.href,'sort',this.value));
    });

    //每页数量
    $("select[name=pagesize]").on('change',function () {
        window.location.href=(setUrlParam(window.location.href,'pagesize',this.value));
    });

    //设置url中参数值
    function setUrlParam(location,name,value) {
        var url = location;
        var splitIndex = url.indexOf("?") + 1;
        var paramStr = url.substr(splitIndex, url.length);
        var newUrl = url.substr(0, splitIndex);
        // - if exist , replace
        var arr = paramStr.split('&');
        for (var i = 0; i < arr.length; i++) {
            var kv = arr[i].split('=');
            if (kv[0] == name) {
                newUrl += kv[0] + "=" + value;
            } else {
                if (kv[1] != undefined) {
                    newUrl += kv[0] + "=" + kv[1];
                }
            }
            if (i != arr.length - 1) {
                newUrl += "&";
            }
        }
        // - if new, add
        if (newUrl.indexOf(name) < 0) {
            newUrl += splitIndex == 0 ? "?" + name + "=" + value : "&" + name + "=" + value;
        }
        return newUrl;
    }

    /**
     * 切换隐藏
     */
    $(".toggle").on('click',function () {
        if(sessionStorage.displayType==1 || typeof sessionStorage.displayType=='undefined'){
            document.getElementById('search-area').style.display='none';
            sessionStorage.displayType=0;
        }else{
            document.getElementById('search-area').style.display='block';
            sessionStorage.displayType=1;
        }
    });
    if(sessionStorage.displayType==='0'){
        document.getElementById('search-area').style.display='none';
    }

    //导出excel
    $('#excel').click(function(){
        var url=window.location.href;
        location.href=setUrlParam(url,'export','true');
    });

</script>